/**
 * 
 */
package org.sishoras.logic;

import java.util.Date;
import java.util.List;

import org.sishoras.dao.DAOFactory;
import org.sishoras.interceptors.DAOInterceptor;
import org.sishoras.modelo.NivelPagamentoProfessor;
import org.sishoras.modelo.Professor;
import org.vraptor.annotations.Component;
import org.vraptor.annotations.InterceptedBy;

/**
 * This class is part of the SisHoras project	
 * Creation:  30/12/2008 20:33:02
 * TODO
 * 
 * @author Walker Rabelo
 * 
 */
@Component
@InterceptedBy(DAOInterceptor.class)
public class ProfessorLogic {

	private final DAOFactory daoFactory;
	
	private Professor professor;	
	private List<Professor> professores;
	
	private double valorHora;
	private Date inicio;
	
	
	public ProfessorLogic(DAOFactory factory) {
		// TODO Auto-generated constructor stub
		this.daoFactory = factory;
	}
	public void form(){
		
	}	
	public void editar(Professor professor){
		this.professor = this.daoFactory.getProfessorDao().carregar(professor.getId());
	}	
	public void armazena(Professor professor){
		System.out.println("Salvando...");
		
		NivelPagamentoProfessor nivelPagamentoProfessor = null;
		
		
		if(professor.getNiveisPagamentosProfesores().isEmpty()){
			nivelPagamentoProfessor = new NivelPagamentoProfessor();
			nivelPagamentoProfessor.setInicioVigencia(inicio);
			nivelPagamentoProfessor.setValorHoraAula(valorHora);
		}else{
			
		}
			
		
		this.daoFactory.beginTransaction();
		this.daoFactory.getProfessorDao().atualiza(professor);
		this.daoFactory.commit();
	}
	public void remove(Professor professor){
		this.daoFactory.beginTransaction();
		this.daoFactory.getProfessorDao().remover(professor);
		this.daoFactory.commit();
	}
	public void lista(){
		professores = this.daoFactory.getProfessorDao().getLista();
	}

	/**
	 * @return the professores
	 */
	public List<Professor> getProfessores() {
		return professores;
	}

	public Professor getProfessor() {
		return professor;
	}
}
